-- ======================================================================
-- Hell Lua Bus
-- 
-- Copyright 2012-2013Hell-Prototypes
--
-- http://www.hellprototypes.com/
--
-- This is free software, licensed under the terms of the GNU General
-- Public License as published by the Free Software Foundation.
-- ======================================================================
spi = require "mod_fw_spi"

SPI_SS_PIN   = 4

if not spi.device_open() then
	print("<ISP> spi.device_open fail")
	return
end

if not spi.init(5,6,7,SPI_SS_PIN) then
	print("<ISP> spi.io_init fail")
	return
end

--reset
spi.pin_reset( SPI_SS_PIN )

ret = spi.send_8bit(0xC0)
print("spi.send_8bit ret1 = " .. ret)

spi.pin_set( SPI_SS_PIN )

--write
spi.pin_reset( SPI_SS_PIN )

ret = spi.send_8bit(0x02)
print("spi.send_8bit ret1 = " .. ret)

ret = spi.send_8bit(0x36)
print("spi.send_8bit ret2 = " .. ret)

ret = spi.send_8bit(0x5)
print("spi.send_8bit ret2 = " .. ret)

ret = spi.send_8bit(0x7)
print("spi.send_8bit ret2 = " .. ret)

ret = spi.send_8bit(0x9)
print("spi.send_8bit ret2 = " .. ret)

spi.pin_set( SPI_SS_PIN )

--read
spi.pin_reset( SPI_SS_PIN )

ret = spi.send_8bit(0x03)
print("spi.send_8bit ret1 = " .. ret)

ret = spi.send_8bit(0x36)
print("spi.send_8bit ret2 = " .. ret)

ret = spi.send_8bit(0x01)
print("spi.send_8bit ret2 = " .. ret)

ret = spi.send_8bit(0x02)
print("spi.send_8bit ret2 = " .. ret)

ret = spi.send_8bit(0x04)
print("spi.send_8bit ret2 = " .. ret)

spi.pin_set( SPI_SS_PIN )

if not spi.device_close() then
	print("<ISP> spi.device_close fail")
end